<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
    <!-- 上传图片css -->
    <!--    <link rel="stylesheet" href="../lib/upload/upload.css" media="all">-->
    <style>
        body {
            background-color: #ffffff;
        }

        .layui-input-block {
            width: 840px;
            margin-bottom: 10px;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">



    <input type="hidden" id="shopId" name="shopId">

    <div class="layui-form-item">
        <label class="layui-form-label" required>消费项目名称</label>
        <div class="layui-input-block">
            <input type="text" name="consumptionItems" lay-verify="required" lay-reqtext="消费项目名称不能为空" placeholder="请输入消费项目名称" autocomplete="off"
                   class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
            <button class="layui-btn layui-btn-normal" id="cancel">取消</button>
        </div>
    </div>

</div>
<!-- 上传图片jquery -->
<script src="../lib/upload/jquery.min.js" charset="utf-8"></script>
<script src="../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="../js/public-config2.js" charset="utf-8"></script>
<script src="../js/common.js" charset="utf-8"></script>
<!-- 上传图片js -->
<script src="../lib/upload/jquery.upload.min.js" charset="utf-8"></script>
<script>


    let memberId = localStorage.getItem('memberId');

    $('#shopId').val(memberId)

    layui.use(['form', 'layedit', 'upload', 'tableSelect'], function () {
        var form = layui.form
            , layer = layui.layer
            , upload = layui.upload
            , $ = layui.$;

        //初始化表单，要加上，不然刷新部分组件可能会不加载
        form.render();
        var iframeIndex = parent.layer.getFrameIndex(window.name);
        //创建一个编辑器

        //自定义验证规则
        //监听提交
        form.on('submit(demo1)', function (data) {
            $.ajax({
                type: "POST", //提交方式
                url: "../barItem/insert",//路径
                contentType: "application/json;charset=utf-8",
                data: JSON.stringify(data.field),//数据，这里使用的是Json格式进行传输
                dataType: "json",
                success: function (result) {//返回数据根据结果进行相应的处理
                    if (result.code == "200") {
                        var index = layer.msg("成功", {
                            time: 800 //如果不配置，默认是3秒）
                        }, function () {
                            // 关闭弹出层
                            layer.close(index);
                            parent.layer.close(iframeIndex);
                        })
                    } else {
                        layer.msg(result.msg);
                    }
                }
            });
            return false;
        });


        //退出
        $('#cancel').on("click", function () {
            parent.layer.close(iframeIndex);
        });

    });
</script>
</body>
</html>